package com.jman.front.util;

import cn.hutool.core.bean.BeanUtil;
import com.jman.front.dto.UserDTO;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class InfoClient {
    public static UserDTO getUserInfo(HttpServletRequest request, StringRedisTemplate stringRedisTemplate){
        String token = null;
        try {
            token = request.getHeader("authorization");
        } catch (Exception e) {
            return null;
        }
        Map<Object, Object> map = stringRedisTemplate.opsForHash().entries("login:user:" + token);
        UserDTO userDTO = BeanUtil.fillBeanWithMap(map, new UserDTO(), false);
        System.out.println(userDTO);
        return userDTO;
    }
}
